package com.xuan.webfinally.service.impl;

import com.xuan.webfinally.entity.SlopeWarningInfo;
import com.xuan.webfinally.entity.WarningInfo;
import com.xuan.webfinally.entity.clickDTO;
import com.xuan.webfinally.entity.clickWindow;
import com.xuan.webfinally.entity.gaojingtanchuang;
import com.xuan.webfinally.mapper.SlopeInfoMapper;
import com.xuan.webfinally.mapper.SlopeSensorListMapper;
import com.xuan.webfinally.mapper.SlopeWarningInfoMapper;
import com.xuan.webfinally.mapper.SysDeptMapper;
import com.xuan.webfinally.mapper.SysUserMapper;
import com.xuan.webfinally.service.ISlopeWarningInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.InvocationTargetException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 预警信息表 服务实现类
 * </p>
 *
 * @author gyuxuan
 * @since 2025-05-18
 */
@Service
public class SlopeWarningInfoServiceImpl extends ServiceImpl<SlopeWarningInfoMapper, SlopeWarningInfo> implements ISlopeWarningInfoService {

    @Autowired
    private SlopeWarningInfoMapper mapper;



    @Autowired
    private SysDeptMapper sysDeptMapper;

    @Autowired
    private SysUserMapper sysUserMapper;

    @Autowired
    private SlopeSensorListMapper  slopeSensorListMapper;
    @Autowired
    private SlopeWarningInfoMapper slopeWarningInfoMapper;


    @Autowired
    private SlopeInfoMapper  slopeInfoMapper;

    @Override
    public int getTotal(String username,Long deptId) {
        if (deptId == 100L)
        {
            return mapper.countAlls();
        }
        return mapper.countAll(deptId);


    }

    @Override
    public List<WarningInfo> queryWarningList(String username,Long deptId) {
        if (deptId == 100L)
        {
            return mapper.getWarningInfoBy(deptId);
        }
        return mapper.getWarningInfoBy(deptId);
    }

    @Override
    public int getTotalLd(String username,Long deptId) {
        if (username == "admin")
        {
            return slopeSensorListMapper.getAllLd(deptId);
        }
        Long DeptId = sysUserMapper.selectDeptId(username);
        return slopeSensorListMapper.getAllLd(deptId);
    }

    @Override
    public List<gaojingtanchuang> getGaojingTanchuang(String username,Long deptIds) {

        List<gaojingtanchuang> gaojingtanchuangs = new ArrayList<gaojingtanchuang>();
//        Long deptId;

//        if (username.equals("admin"))
//        {
//            deptId = deptIds;
//        }else {
//            deptId = sysUserMapper.selectDeptId(username);
//        }
        if (deptIds == 100L)
        {
            gaojingtanchuangs = slopeWarningInfoMapper.selectQuanbu();
        }else{
             gaojingtanchuangs = slopeWarningInfoMapper.selectSingle(deptIds);
        }
        System.out.println("这个方法走了。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。"+deptIds);

        System.out.println("deptId:"+deptIds);

        for (int i = 0; i < gaojingtanchuangs.size(); i++) {
            // 给每个对象中的手机号进行赋值
            gaojingtanchuangs.get(i).setPhoneNumber(sysUserMapper.selectPhoneById(deptIds));
        }

//        LocalDateTime warningTime = slopeWarningInfoMapper.selectTime(deptId);
//        gaojingtanchuang.setWarningTime(warningTime);
//
//        gaojingtanchuang.setWarningInfo(slopeWarningInfoMapper.getGaojingTanchuang(warningTime));
//
//        gaojingtanchuang.setSlopeName(slopeWarningInfoMapper.getGaojingTanchuangs(warningTime));
//
//        String updateBy = slopeWarningInfoMapper.selectName(warningTime);
//        gaojingtanchuang.setUpdateBy(updateBy);
//
//        gaojingtanchuang.setPhoneNumber(sysUserMapper.selectPhone(updateBy));
//
//        gaojingtanchuang.setWarningLevel(slopeWarningInfoMapper.getGaojingTanchuangLevel(warningTime));

        System.out.println("gaojingTanchuang:gggggggggggggggggggggggggggggg"+deptIds);
        System.out.println("gaojingTanchuang:gggggggggggggggggggggggggggggg"+gaojingtanchuangs);
        return gaojingtanchuangs;
    }

    @Override
    public clickWindow getTotalClinck(String username, String choice,Long deptIds) throws InvocationTargetException, IllegalAccessException {
        Long deptId;
        if (username == "admin")
        {
            deptId = deptIds;
        }else {
            deptId = sysUserMapper.selectDeptId(username);
        }
//        deptId = sysUserMapper.selectDeptId(username);
        clickWindow clickWindow = new clickWindow();
        switch (choice){
            case "1":
                clickDTO clickDTO = slopeInfoMapper.findMessageOne(deptId);
                BeanUtils.copyProperties(clickWindow, clickDTO);
                clickWindow.setPhoneNumber(sysUserMapper.selectPhone(username));
                clickWindow.setDeptName(sysDeptMapper.getToName(deptId));
                break;
            case "2":

                break;
        }


//        slopeInfoMapper.findMessageThree();
//        slopeInfoMapper.findMessageFour();
//        slopeInfoMapper.findMessageFive();
        return clickWindow;
    }


}
